package com.jml.zlhq.app.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONObject;

import android.app.Activity;
import android.text.Html;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.jml.zlhq.app.R;
import com.jml.zlhq.app.AppContext;
import com.jml.zlhq.app.util.UIUtil;

public class CityAdapter extends IBaseAdapter {
	private List<JSONObject> itemList;
	private AppContext appContext;
	private Map<Integer,String> titles = new HashMap<Integer,String>();

	public CityAdapter(Activity activity, List<JSONObject> itemList) {
		this.itemList = itemList;
		this.appContext = (AppContext) activity.getApplication();
	}

	@Override
	public int getCount() {
		int count  = itemList == null ? 0 : itemList.size();
		return count+2;
	}

	@Override
	public Object getItem(int position) {
		return itemList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	
	static class ViewHolder {
		public TextView title;
	}

	@Override
	public View getView(int position, View convertView, final ViewGroup parent) {
		
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			int layoutId = R.layout.city_item;
			convertView = LayoutInflater.from(appContext).inflate(layoutId, null);
			viewHolder.title = (TextView) convertView.findViewById(R.id.city_item_text);
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if(position==0){
			viewHolder.title.setPadding(0, UIUtil.dip2px(appContext, 10), 0, UIUtil.dip2px(appContext, 10));
			viewHolder.title.setBackgroundColor(appContext.getResources().getColor(R.color.graywhite));
			viewHolder.title.setTextSize(TypedValue.COMPLEX_UNIT_PX,appContext.getResources().getDimension(R.dimen.text_13));
			viewHolder.title.setText("定位城市");
			titles.put(position, "定位城市");
		}else if(position==1){
			viewHolder.title.setPadding(0, UIUtil.dip2px(appContext, 18), 0, UIUtil.dip2px(appContext, 18));
			viewHolder.title.setBackgroundColor(appContext.getResources().getColor(R.color.white));
			viewHolder.title.setTextSize(TypedValue.COMPLEX_UNIT_PX,appContext.getResources().getDimension(R.dimen.text_16));
			viewHolder.title.setText(Html.fromHtml("你当前的城市：<font color='#ff668c'>成都</font>"));
		}else{
			
		}
		return convertView;
	}

}
